<template>
  <div :class="className" :style="{height:height,width:width}"></div>
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '100%'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        title: {
          text: '设备分布情况',
          textStyle: {
            color: 'yellow'
          },
          x: '8%',
          y: '8%'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        grid: {
          top: '25%',
          left: '20%',
          containLabel: true
        },
        xAxis: [{
          type: 'category',
          data: ['义安区', '铜官区', '市辖区', '郊区', '枞阳县'],
          textStyle: {
            color: 'white'
          },
          axisTick: {
            alignWithLabel: true
          }
        }],
        yAxis: [{
          type: 'value',
          scale : true,
          max : 1500,
          min : 0,
          splitNumber : 3,
          boundaryGap : [ 0.2, 0.2 ],
          axisTick: {
            show: false
          }
        }],
        series: [{
          name: '设备分布情况',
          type: 'bar',
          stack: 'vistors',
          barWidth: '60%',
          data: [1163, 1056, 589, 417, 687],
          animationDuration: 100
        }]
      })
    }
  }
}
</script>
